# from util.Sql_df import SQLServer_df
# from util.sql_pyodbc import SQLServer_pyodbc

# sqldf = SQLServer_df('AnJiServer')
# sqlpyodbc = SQLServer_pyodbc('AnJiServer')

from api import sqlpyodbc,sqldf

# 获取所有角色
def GetRoles():
    sql = f'SELECT role_id,role_name FROM roles'
    try:
        return sqldf.Query(sql)
    except:
        return None
# 添加角色
def Add_role(rolename):
    sql = f'''
        INSERT INTO roles(role_name) VALUES('{rolename}');
    '''
    try:
        return sqlpyodbc.execute(sql)
    except:
        return None

# 获取所有菜单和按钮
def Get_menus_buttons():
    sql='select acl_id,parent_id,acl_name,acl_type,title from acl'
    try:
        return sqldf.Query(sql)
    except:
        return None

# 根据角色id获取菜单和按钮
def Get_menus_buttons_by_roleid(role_id):
    sql=f'select acl_id from role_acl where role_id={role_id}'
    try:
        return sqldf.Query(sql)
    except:
        return None

# 添加用户权限
def Add_role_acls(sqlList):
    try:
        return sqlpyodbc.execute_transaction(sqlList)
    except:
        return False
